package com.taptech.doufu.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.taptech.doufu.R
import com.taptech.doufu.ui.activity.me.VoucherActivity
import kotlinx.android.synthetic.main.adapter_voucher_layout.view.*

class VoucherAdapter(context:Context): BaseRecyclerAdappter<VoucherActivity.VoucherBean,VoucherAdapter.ViewHolder>(context){

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.adapter_voucher_layout,null)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        val item = dataList[position]
        holder.itemView.tvAmount.text = "${item.amount/100}"
        if (item.min_amount > 0) {
            holder.itemView.tvDesc.text = "满${item.min_amount/100}元可用"
            holder.itemView.tvDesc.visibility = View.VISIBLE
        }else{
            holder.itemView.tvDesc.visibility = View.GONE
        }
        holder.itemView.tvTime.text = "有效期至：${item.expire_date}"
        if (item.select){
            holder.itemView.ivSelect.setBackgroundResource(R.drawable.icon_voucher_st)
        }else{
            holder.itemView.ivSelect.setBackgroundResource(R.drawable.icon_voucher)
        }

    }

    class ViewHolder(view: View): RecyclerView.ViewHolder(view)
}